import grails.orm.PagedResultList

class HotelController {

    def index = {
        request.bookings = Booking.findAllByUser(session.LOGIN_USER)
    }

    def search = {
        String searchString = !params.searchString ? "" : params.searchString
        Map paginateParams = [max: Integer.parseInt(params.max), offset: Integer.parseInt(params.offset)]

        PagedResultList hotels = Hotel.search(searchString, paginateParams)

        session.searchString = searchString
        session.hotels = hotels
        session.hotelCount = hotels.totalCount
        session.max = params.max ?: session.max
        session.offset = params.offset ?: session.offset

        render(template: 'searchResults')
    }
}